using System;
using EPiServer.Common;
using EPiServer.Common.Queries;
using EPiServer.Common.Security;
using EPiServer.Community.Poll;
using EPiServer.Community.Poll.Queries;

namespace EPiAbstractions.Community.Poll
{
    public class PollHandlerFacade : IPollHandlerFacade
    {
        private static PollHandlerFacade _instance;

        public PollHandlerFacade()
        {
            PollHandler.PollAdded += OnPollAdded;
            PollHandler.PollUpdated += OnPollUpdated;
            PollHandler.PollRemoved += OnPollRemoved;
        }

        public static PollHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new PollHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IPollHandlerFacade Members

        public event EPiServerCommonEventHandler PollAdded;
        public event EPiServerCommonEventHandler PollUpdated;
        public event EPiServerCommonEventHandler PollRemoved;

        public virtual EPiServer.Community.Poll.Poll AddPoll(EPiServer.Community.Poll.Poll poll)
        {
            return PollHandler.AddPoll(poll);
        }

        public virtual void UpdatePoll(EPiServer.Community.Poll.Poll poll)
        {
            PollHandler.UpdatePoll(poll);
        }

        public virtual void RemovePoll(EPiServer.Community.Poll.Poll poll)
        {
            PollHandler.RemovePoll(poll);
        }

        public virtual EPiServer.Community.Poll.Poll GetPoll(Int32 id)
        {
            return PollHandler.GetPoll(id);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, out Int32 totalItems, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, NullValueAction siteNullAction, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, siteNullAction, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, NullValueAction siteNullAction, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, siteNullAction, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, DateTime activeDate, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, activeDate, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, DateTime activeDate, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, activeDate, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, DateTime activeDate,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, activeDate, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, DateTime activeDate, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, activeDate, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                               PollStatus pollStatus, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, siteNullAction, pollStatus, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                               PollStatus pollStatus, out Int32 totalItems, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, siteNullAction, pollStatus, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, DateTime activeDate, PollStatus pollStatus,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, activeDate, pollStatus, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, DateTime activeDate, PollStatus pollStatus,
                                               out Int32 totalItems, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, activeDate, pollStatus, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, PollStatus pollStatus, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, pollStatus, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, PollStatus pollStatus, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, pollStatus, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, DateTime activeDate, PollStatus pollStatus,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, activeDate, pollStatus, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, DateTime activeDate, PollStatus pollStatus, out Int32 totalItems,
                                               PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, activeDate, pollStatus, out totalItems, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                               DateTime activeDate, PollStatus pollStatus, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, siteNullAction, activeDate, pollStatus, sortOrder);
        }

        public virtual PollCollection GetPolls(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                               DateTime activeDate, PollStatus pollStatus, out Int32 totalItems, PollSortOrder[] sortOrder)
        {
            return PollHandler.GetPolls(page, pageSize, sites, siteNullAction, activeDate, pollStatus, out totalItems, sortOrder);
        }

        public virtual ChoiceCollection GetChoices(EPiServer.Community.Poll.Poll poll)
        {
            return PollHandler.GetChoices(poll);
        }

        public virtual Choice GetChoice(Int32 choiceId)
        {
            return PollHandler.GetChoice(choiceId);
        }

        public virtual VoteCollection GetVotes(ChoiceCollection choices, Int32 page, Int32 pageSize, VoteSortOrder[] order)
        {
            return PollHandler.GetVotes(choices, page, pageSize, order);
        }

        public virtual VoteCollection GetVotes(ChoiceCollection choices, Int32 page, Int32 pageSize, out Int32 totalItems,
                                               VoteSortOrder[] order)
        {
            return PollHandler.GetVotes(choices, page, pageSize, out totalItems, order);
        }

        public virtual void Vote(Vote vote)
        {
            PollHandler.Vote(vote);
        }

        public virtual Boolean HasVoted(IUser user, EPiServer.Community.Poll.Poll poll)
        {
            return PollHandler.HasVoted(user, poll);
        }

        public virtual PollCollection GetQueryResult(PollQuery query)
        {
            return PollHandler.GetQueryResult(query);
        }

        public virtual PollCollection GetQueryResult(PollQuery query, Int32 page, Int32 pageSize)
        {
            return PollHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual PollCollection GetQueryResult(PollQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return PollHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual ChoiceCollection GetQueryResult(ChoiceQuery query)
        {
            return PollHandler.GetQueryResult(query);
        }

        public virtual ChoiceCollection GetQueryResult(ChoiceQuery query, Int32 page, Int32 pageSize)
        {
            return PollHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual ChoiceCollection GetQueryResult(ChoiceQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return PollHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual VoteCollection GetQueryResult(VoteQuery query)
        {
            return PollHandler.GetQueryResult(query);
        }

        public virtual VoteCollection GetQueryResult(VoteQuery query, Int32 page, Int32 pageSize)
        {
            return PollHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual VoteCollection GetQueryResult(VoteQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return PollHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        #endregion

        public virtual void OnPollAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (PollAdded != null)
                PollAdded(sender, e);
        }

        public virtual void OnPollUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (PollUpdated != null)
                PollUpdated(sender, e);
        }

        public virtual void OnPollRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (PollRemoved != null)
                PollRemoved(sender, e);
        }
    }
}